走過路過千萬不要錯過自己的發票有沒有中獎了,中獎環節應該是大家最想要了解的XD
依照財政部的電子發票應用規格書

記得 invTerm 只能輸入雙月數
我們來看一下 tw_invoice 的程式碼
def get_lottery_numbers(
        self, invoice_term: str
    ) -> Union[LotteryNumberResponse, dict]:
        """查詢中獎發票號碼清單 v0.2"""
        URL = build_api_url("invapp")
        VERSION = 0.2
        if not validate_invoice_term(invoice_term):
            raise ValueError(f"Invalid invoice_term: {invoice_term}")
        data = {
            "version": VERSION,
            "action": "QryWinningList",
            "invTerm": invoice_term,
            "UUID": self.uuid,
            "appID": self.app_id,
        }
        results = check_api_error(
            self.session.post(URL, data=data, timeout=self.timeout)
        )
        if not self.skip_validation:
            results = LotteryNumberResponse.parse_obj(results)
        return results
查詢中獎號碼和金額真的非常簡單,只要輸入你想查詢的發票期別即可

回傳的參數:


注意財政部回傳連金額都是給字串(有一點不合理),若要計算中獎發票金額記得作轉換
趕快查詢看看手邊的發票有沒有中獎吧!
範例程式碼參考